/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package networkrespnse;

import core.ParameterDecoder;
import core.RuntimeData;
import utils.Utils;

/**
 *
 * @author Kvest
 */
public class ChangeState extends Response {
    private String state;
    private int orderID;
    
    public ChangeState(byte[] data)
    {
        super(CHANGE_STATE);
        state = RuntimeData.DRIVER_STATE_FREE;
        orderID = 0;
        
        parse(data);
    }
    
    protected void parse(byte[] data)
    {
        byte[] body = ParameterDecoder.getTransferBody(data);
        int index,size;
        
        //Пропускаем название класса
        byte[] temp = new byte[4];
        index = 0;
        for (int i=0;i<4;i++)
        {
            temp[i] = body[index++];
        }
        index += Utils.byteToInt(temp);
       
        //state
        for (int i=0;i<4;i++)
        {
            temp[i] = body[index++];
        }
        size = Utils.byteToInt(temp);
        temp = new byte[size];
        for (int i=0;i<size;i++)
        {
            temp[i] = body[index++];
        }
        state = Utils.byteToString(temp);
        
        //orderID
        temp = new byte[4];
        for (int i=0;i<4;i++)
        {
            temp[i] = body[index++];
        }
        orderID = Utils.byteToInt(temp);     
    }

    public int getOrderID() {
        return orderID;
    }

    public String getState() {
        return state;
    }
}
